package com.jk.hly.service.impl;

import com.jk.hly.bean.HlyUser;
import com.jk.hly.mapper.HlyTreeMapper;
import com.jk.hly.service.HlyRegisterService;

import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

@Service
public class HlyRegisterServiceImpl  implements HlyRegisterService {

    @Resource
    JavaMailSender mailSender;

    @Resource
    private HlyTreeMapper  treeMapper;

    @Override
    public String userRegister( String email, String code) {
        MimeMessage mimeMailMessage=mailSender.createMimeMessage();
        MimeMessageHelper mimeMessageHelper=new MimeMessageHelper(mimeMailMessage);
        try {
            mimeMessageHelper.setFrom("2462764837@qq.com");
            mimeMessageHelper.setTo(email);
            mimeMessageHelper.setSubject("注册使用");
            mimeMessageHelper.setText("<html><head></head><body><h1>hello!!欢迎注册</h1><p>验证码为："+code+"</p>" ,true);
            mailSender.send(mimeMailMessage);

            return "1";
        } catch (MessagingException e) {
            e.printStackTrace();
        }
        return "2";
    }

    @Override
    public void userZhuCe(String phone) {
        HlyUser user=new HlyUser();
        user.setPhone(phone);

        treeMapper.addUser(user);
    }
}
